package com.lovepick.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.baidu.mapapi.MKPoiInfo;
import com.lovepick.R;

public class PoiInfoAdapter extends BaseAdapter
{
	private ArrayList<MKPoiInfo> mPoiInfos;
	private Context mContext;
	private LayoutInflater mInflater;
	
	public PoiInfoAdapter(Context context, ArrayList<MKPoiInfo> poiInfos)
	{
		this.mContext = context;
		this.mPoiInfos = poiInfos;
		this.mInflater = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount()
	{
		// TODO Auto-generated method stub
		return mPoiInfos.size();
	}

	@Override
	public Object getItem(int position)
	{
		// TODO Auto-generated method stub
		return mPoiInfos.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		// TODO Auto-generated method stub
		MKPoiInfo info = mPoiInfos.get(position);
		ViewHolder holder = null;
		
		if (null == convertView)
		{
			convertView = mInflater.inflate(R.layout.poi_res_item, null);
			holder = new ViewHolder();
			holder.name = (TextView) convertView.findViewById(R.id.list_poi_name);
			holder.addr = (TextView) convertView.findViewById(R.id.list_poi_addr);
			convertView.setTag(holder);			
		}
		else
		{
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.name.setText(info.name);
		holder.addr.setText(info.address);
		return convertView;
	}
	
	static class ViewHolder
	{
		public TextView name, addr;
	}

}
